<template>
	<view class="pages-a">
		<!-- 顶部自定义导航 -->
		<tn-nav-bar fixed :isBack="false" :bottomShadow="false" backgroundColor="#FFFFFF">
			<view class="custom-nav tn-flex tn-flex-col-center tn-flex-row-left">
				<!-- 图标logo -->
				<view class="custom-nav__back" @click="tn('/pageA/about/about')">
					<view class="logo-pic png-sussuspension1"
						style="background-image:url('http://gyh7790.oss-cn-beijing.aliyuncs.com/buerkeji/mp/20241118/2a42c4a5a78847f481703a07c0e944e9.png')">
						<view class="logo-image ">
						</view>
					</view>
				</view>
				<!-- 搜索框 -->
			<!-- 	<view class="custom-nav__search tn-flex tn-flex-col-center tn-flex-row-center"
					@click="tn('/pageA/search/search')">
					<view class="custom-nav__search__box tn-flex tn-flex-col-center tn-flex-row-left"
						style="background-color: rgba(230,230,230,0.3);">
						<view class="tn-color-gray" style="width: 100%;">
							<tn-notice-bar :list="searlist" mode="vertical" leftIconName="search"
								:duration="6000"></tn-notice-bar>
						</view>
					</view>
				</view> -->
					<view class="custom-nav__search tn-flex tn-flex-col-center tn-flex-row-center"
						>
						<view class="custom-nav__search__box tn-flex tn-flex-col-center"
							>
							<view class="tn-text-xxl fon-text-large tn-text-bold clamp-text-1 tn-text-justify">
								<text class="">每日更新，精选好文</text>
							</view>
						</view>
					</view>
			</view>
		</tn-nav-bar>

		<!-- 顶部自定义导航 -->
		<view class="tabs-fixed tn-bg-white">
			<view class="tn-flex tn-flex-col-between tn-flex-col-center tn-padding-top-sm"
				:style="{marginTop: vuex_custom_bar_height + 'px'}">
				<view class="justify-content-item" style="width: 100vw;overflow: hidden;">
					<tn-tabs :list="tags" name="label" :current="current" :isScroll="true" activeColor="#000"
						:bold="true" :fontSize="40" :badgeOffset="[20, 50]" @change="tabChange"
						backgroundColor="#FFFFFF" :height="70"></tn-tabs>
				</view>
				<!-- <view class="justify-content-item" style="width: 13vw;overflow: hidden;"
					@click="tn('/homePages/xxxxx')">
					<picker @change="bindPickerChange" :value="index" :range="array">
						<view class="tn-color-black tn-round"
							style="font-size: 45rpx;margin-top: -5rpx;margin-left: 15rpx;">
							<text class="tn-icon-level tn-padding-xs"></text>
						</view>
					</picker>
				</view> -->
			</view>
		</view>

		<view class="" :style="{paddingTop: vuex_custom_bar_height + 'px'}" style="margin-top: 130rpx;">

			<swiper class="card-swiper" :circular="true" :autoplay="false" duration="500" interval="18000"
				@change="cardSwiper">
				<swiper-item v-for="(item,index) in swiperList" :key="index" :class="cardCur==index?'cur':''">
					<view class="swiper-item image-banner" @click="tn(`/pageA/news/news?id=${item.id}`)">
						<image :src="item.url" mode="aspectFill"></image>
					</view>
					<view class="swiper-item-text" @click="tn(`/pageA/news/news?id=${item.id}`)">
						<view class="text-sussuspension">
							<view class="tn-text-bold tn-color-white clamp-text-2" style="font-size: 34rpx;">{{item.title}}</view>
						</view>
					</view>
				</swiper-item>
			</swiper>
			<view class="indication">
				<block v-for="(item,index) in swiperList" :key="index">
					<view class="spot" :class="cardCur==index?'active':'tn-bg-black'"
						:style="'background-color: '+ item.color +''"></view>
				</block>
			</view>


			<view class="" v-if="news.length">
				<view class="">
					<block v-for="(item,index) in news" :key="index">
						<!-- 单图大图文 -->
						<block v-if="item.imgLen == 1">
							<view class="article-shadow tn-margin tn-padding-sm"
								@click="tn(`/pageA/news/news?id=${item.id}`)">
								<view class="image-pic" :style="'background-image:url(' + item.url + ')'">
									<view class="image-design">
									</view>
								</view>
								<view class="tn-margin-top tn-padding-bottom-sm">
									<view class="tn-text-xxl fon-text-large tn-text-bold clamp-text-1 tn-text-justify">
										<text class="">{{ item.title }}</text>
									</view>

									<view class="tn-flex tn-flex-row-between tn-flex-col-between tn-margin-top-sm">
										<!-- <view v-for="(label_item,label_index) in item.label" :key="label_index"
										class="justify-content-item tn-tag-content__item tn-margin-right tn-text-sm tn-text-bold">
										<text class="tn-tag-content__item--prefix">#</text> {{ label_item }}
									</view> -->
										<view class="justify-content-item tn-color-gray tn-text-center"
											style="padding-top: 5rpx;">
											<text class="tn-icon-fire tn-text-lg" style="padding-right: 5rpx;"></text>
											<text class="tn-padding-right tn-text-df">{{item.readNum}}次观看</text>
											<text class="tn-icon-moments tn-text-lg"
												style="padding-right: 5rpx;"></text>
											<text class="tn-text-df">{{item.shareNum}}人 (转发得<text
													class="tn-color-red">1-100</text>红包)</text>

										</view>
									</view>
								</view>
							</view>
						</block>
						<!-- 三图图文 -->
						<block v-if="item.imgLen == 3">
							<view class="article-shadow tn-margin" @click="tn(`/pageA/news/news?id=${item.id}`)">
								<view class="" style="padding: 15rpx 10rpx 0 10rpx;">
									<tn-grid hoverClass="none" :col="3">
										<block v-for="(image_item,image_index) in item.imgList" :key="image_index">
											<view class="" style="width: 33.3%;">
												<view class="image-pic tn-margin-xs"
													:style="'background-image:url(' + image_item + ')'">
													<view class="image-article">
													</view>
												</view>
												<!-- <image
					        class="blogger__main-image blogger__main-image--3"
					        :src="image_item"
					        mode="aspectFill"
					      ></image> -->
											</view>
										</block>
									</tn-grid>
								</view>


								<view class="tn-margin-sm tn-padding-bottom-sm">
									<view class="tn-text-xxl fon-text-large tn-text-bold clamp-text-1 tn-text-justify">
										<text class="">{{ item.title }}</text>
									</view>
									<!-- <view class="tn-padding-top-xs" style="min-height: 90rpx;">
					  <text class="tn-text-df tn-color-gray clamp-text-2 tn-text-justify">
					    {{ item.desc }}
					  </text>
					</view> -->
									<view class="tn-flex tn-flex-row-between tn-flex-col-between tn-margin-top-sm">
										<!-- <view v-for="(label_item,label_index) in item.label" :key="label_index"
											class="justify-content-item tn-tag-content__item tn-margin-right tn-text-sm tn-text-bold">
											<text class="tn-tag-content__item--prefix">#</text> {{ label_item }}
										</view> -->
										<view class="justify-content-item tn-color-gray tn-text-center"
											style="padding-top: 5rpx;">
											<text class="tn-icon-fire tn-text-lg" style="padding-right: 5rpx;"></text>
											<text class="tn-padding-right tn-text-df">{{ item.readNum }}次观看</text>
											<text class="tn-icon-like-lack tn-text-lg"
												style="padding-right: 5rpx;"></text>
											<text class="tn-text-df">{{item.shareNum}}人转发</text>
										</view>
									</view>
								</view>
							</view>
						</block>
					</block>
				</view>
			</view>

			<view class="" v-if="!news.length">
				<view class="tn-text-center" style="font-size: 300rpx;padding-top: 200rpx;">
					<text class="tn-icon-clip tn-color-gray--disabled"></text>
				</view>
				<view class="tn-color-gray tn-text-center tn-text-lg">这里没内容了</view>
			</view>

		</view>

		<view class='tn-tabbar-height'></view>
		<view class="bg-tabbar-shadow"></view>

	</view>


</template>

<script>
	export default {
		name: 'PagesA',
		data() {
			return {
				// 筛选
				index: 1,
				array: ['按时间推荐', '按热度推荐', '随机推荐'],
				current: 0,
				page: 1,
				tags: [],
				searlist: [
					'搜索 最新资讯',
					'搜索 生活健康',
					'搜索 搞笑生活',
					'搜索 美女图文'
				],
				cardCur: 0,
				swiperList: [],
				news: [],
				tagId: 0
			}
		},
		created() {
			this.getArticle(true)
			this.getTags()
			this.getTops()
		},

		methods: {
			getArticle(isFirst = false) {
				if (isFirst) {
					this.page = 1
					this.news = []
				} else {
					this.page += 1
				}
				this.$api.getArticle({
					tagId: this.tagId,
					page: this.page
				}).then((res) => {
					this.loading = false;
					if (!res.data.list.length) {
						return
					}
					let tempList = res.data.list.map(item => {
						let imgList = item.imgList
						if (!item.imgList) {
							imgList = []
						}
						return {
							...item,
							imgLen: imgList.length,
							url: imgList[0] || ''
						}
					})
					let newList = this.news.concat(tempList)
					this.news = newList
				}).catch((err) => {
					console.log(err)
					this.loading = false;
				})
			},
			getTops() {
				this.$api.getTops({
					tagId: this.tagId
				}).then((res) => {
					this.loading = false;
					this.swiperList = res.data.map(item => {
						return {
							...item,
							url: item.imgList[0]
						}
					})
				}).catch((err) => {
					this.loading = false;
				})
			},
			getTags() {
				this.$api.getTags().then((res) => {
					this.loading = false;
					this.tags = res.data
				}).catch((err) => {
					this.loading = false;
				})
			},
			// 筛选
			bindPickerChange: function(e) {
				this.index = e.detail.value
			},

			// 跳转
			tn(e) {
				uni.navigateTo({
					url: e,
				});
			},
			// tab选项卡切换
			tabChange(index) {
				let currentTag = this.tags[index]
				this.tagId = currentTag.id
				this.current = index
				this.getArticle(true)
			},
			// cardSwiper
			cardSwiper(e) {
				this.cardCur = e.detail.current
			},

		}

	}
</script>

<style lang="scss" scoped>
	.pages-a {
		width: 100%;
		height: 100%;
		position: relative;
		// background-image: linear-gradient(to top, #4C3FAE 20%, #6E26BA 80%);
	}

	/* 底部安全边距 start*/
	.tn-tabbar-height {
		min-height: 120rpx;
		height: calc(140rpx + env(safe-area-inset-bottom) / 2);
		height: calc(140rpx + constant(safe-area-inset-bottom));
	}


	/* 底部tabbar假阴影 start*/
	.bg-tabbar-shadow {
		// background-image: repeating-linear-gradient(to top, rgba(0,0,0,0.1) 10rpx, rgba(255,255,255,0) , rgba(255,255,255,0));
		box-shadow: 0rpx 0rpx 400rpx 0rpx rgba(0, 0, 0, 0.25);
		position: fixed;
		bottom: calc(0rpx + env(safe-area-inset-bottom) / 2);
		bottom: calc(0rpx + constant(safe-area-inset-bottom));
		height: 60rpx;
		width: 100vw;
		z-index: 0;
	}

	/* 阴影 start*/
	.home-shadow {
		border-radius: 15rpx;
		box-shadow: 0rpx 0rpx 50rpx 0rpx rgba(0, 0, 0, 0.07);
	}


	/* 自定义导航栏内容 start */
	.custom-nav {
		height: 100%;

		&__back {
			margin: auto 5rpx;
			font-size: 40rpx;
			margin-right: 10rpx;
			margin-left: 30rpx;
			flex-basis: 5%;
		}

		&__search {
			flex-basis: 60%;
			width: 100%;
			height: 100%;

			&__box {
				width: 100%;
				height: 70%;
				padding: 10rpx 0;
				margin: 0 30rpx;
				border-radius: 60rpx 60rpx 0 60rpx;
				font-size: 24rpx;
			}

			&__icon {
				padding-right: 10rpx;
				margin-left: 20rpx;
				font-size: 30rpx;
			}

			&__text {
				// color: #AAAAAA;
			}
		}
	}

	.logo-image {
		z-index: 9999 !important;
		width: 65rpx;
		height: 65rpx;
		position: relative;
	}

	.logo-pic {
		z-index: 9999 !important;
		background-size: cover;
		background-repeat: no-repeat;
		// background-attachment:fixed;
		background-position: top;
		border-radius: 50%;
	}

	/* 自定义导航栏内容 end */

	/* 旋转 */
	.png-sussuspension1 {
		animation: suspension1 12s ease-in-out infinite;
	}

	@keyframes suspension1 {
		0% {
			transform: rotate(0deg);
		}

		100% {
			transform: rotate(360deg);
		}
	}

	.tabs-fixed {
		position: fixed;
		top: 0;
		width: 100%;
		transition: all 0.25s ease-out;
		z-index: 1;
	}

	/* 轮播视觉差 start */
	.card-swiper {
		height: 360rpx !important;
		margin-top: -30rpx;
	}

	.card-swiper swiper-item {
		width: 750rpx !important;
		left: 0rpx;
		box-sizing: border-box;
		padding: 30rpx 30rpx 30rpx 30rpx;
		overflow: initial;
		// border: 1rpx solid blueviolet;
	}

	.card-swiper swiper-item .swiper-item {
		width: 100%;
		display: block;
		height: 100%;
		border-radius: 0rpx;
		transform: scale(0.85);
		transition: all 0.2s ease-in 0s;
		will-change: transform;
		overflow: hidden;
		border-radius: 10rpx;
		// border: 1rpx solid blue;
	}

	.card-swiper swiper-item.cur .swiper-item {
		transform: none;
		transition: all 0.2s ease-in 0s;
		will-change: transform;
	}

	.card-swiper swiper-item .swiper-item2 {
		margin-top: -370rpx;
		width: 620rpx;
		display: block;
		height: 515rpx;
		border-radius: 0rpx;
		transform: translate(240rpx, 0rpx) scale(0.45, 0.45);
		transition: all 0.6s ease 0s;
		will-change: transform;
		overflow: hidden;
		// border: 1rpx solid black;
	}

	.card-swiper swiper-item.cur .swiper-item2 {
		margin-top: -385rpx;
		width: 620rpx;
		transform: translate(210rpx, 0rpx) scale(0.62, 0.62);
		transition: all 0.6s ease 0s;
		will-change: transform;
	}

	.card-swiper swiper-item .swiper-item-text {
		// margin-top: -300rpx;

		// height: 50%;
		// border-radius: 10rpx;
		// transform: translate(0rpx, -40rpx) scale(0.7, 0.7);
		// transition: all 0.6s ease 0s;
		will-change: transform;
		// overflow: hidden;
		position: absolute;
		bottom: 30rpx;
		padding: 10rpx 30rpx;
		background: rgba(0, 0, 0, .5);
		color: #fff;
		width: 92%;
		display: block;
	}

	.card-swiper swiper-item.cur .swiper-item-text {
		// margin-top: -350rpx;
		// width: 100%;
		// transform: translate(0rpx, 0rpx) scale(0.9, 0.9);
		// transition: all 0.6s ease 0s;
		// will-change: transform;
	}

	.image-banner {
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.image-banner image {
		width: 100%;
	}

	/* 轮播指示点 start*/
	.indication {
		z-index: 0;
		width: 100%;
		height: 36rpx;
		position: absolute;
		display: flex;
		flex-direction: row;
		align-items: center;
		justify-content: center;
		// border: 1rpx solid orangered;
	}

	.spot {
		// background-color: #FBBD12;
		top: -80rpx;
		opacity: 0.1;
		width: 30rpx;
		height: 8rpx;
		border-radius: 2rpx;
		margin: 0 6rpx !important;
		left: -238rpx;
		position: relative;
	}

	.spot.active {
		opacity: 1;
		width: 30rpx;
		// background-color: #FBBD12;
	}



	/* 资讯主图 start*/
	.image-article {
		border-radius: 8rpx;
		width: 200rpx;
		height: 200rpx;
		position: relative;
	}

	.image-pic {
		border: 1rpx solid #F8F7F8;
		background-size: cover;
		background-repeat: no-repeat;
		// background-attachment:fixed;
		background-position: top;
		border-radius: 10rpx;
		background-position: center;
	}

	.article-shadow {
		border-radius: 15rpx;
		box-shadow: 0rpx 0rpx 50rpx 0rpx rgba(0, 0, 0, 0.07);
	}

	/* 文字截取*/
	.clamp-text-1 {
		-webkit-line-clamp: 2;
		display: -webkit-box;
		-webkit-box-orient: vertical;
		text-overflow: ellipsis;
		overflow: hidden;
	}

	.clamp-text-2 {
		-webkit-line-clamp: 2;
		display: -webkit-box;
		-webkit-box-orient: vertical;
		text-overflow: ellipsis;
		overflow: hidden;
	}

	/* 标签内容 start*/
	.tn-tag-content {
		&__item {
			display: inline-block;
			line-height: 35rpx;
			color: #1D2541;
			background-color: #F3F2F7;
			border-radius: 10rpx;
			font-size: 22rpx;
			padding: 5rpx 15rpx;

			&--prefix {
				padding-right: 10rpx;
			}
		}
	}


	/* 大单图 start*/
	.tn-blogger-content2 {
		&__wrap {
			padding: 30rpx;
		}

		&__info {
			&__btn {
				margin-right: -12rpx;
				opacity: 0.5;
			}
		}

		&__label {
			&__item {
				line-height: 45rpx;
				padding: 0 20rpx;
				margin: 5rpx 18rpx 0 0;

				&--prefix {
					color: #00FFC8;
					padding-right: 10rpx;
				}
			}

			&__desc {
				line-height: 55rpx;
			}
		}

		&__main-image {
			box-shadow: 0rpx 5rpx 40rpx 0rpx rgba(43, 158, 246, 0.2);
			border-radius: 16rpx;

			&--1 {
				max-width: 690rpx;
				min-width: 690rpx;
				max-height: 400rpx;
				min-height: 400rpx;
			}

			&--2 {
				max-width: 260rpx;
				max-height: 260rpx;
			}

			&--3 {
				height: 212rpx;
				width: 100%;
			}
		}

		&__count-icon {
			font-size: 40rpx;
			padding-right: 5rpx;
		}
	}

	.image-design {
		padding: 160rpx 0rpx;
		font-size: 40rpx;
		font-weight: 300;
		position: relative;
	}

	.image-pic {
		background-size: cover;
		background-repeat: no-repeat;
		// background-attachment:fixed;
		background-position: top;
		border-radius: 10rpx;
		background-position: center;
	}
	.fon-text-large{
		font-size: 42rpx;
	}

	/* 文章内容 end*/
</style>